﻿<!--#include file="../../Lib/base.asp"-->
<!--#include file="../../Lib/Page.asp"-->
<%
	is_plug_login()
	
	dim datadb,datadb2
	dim i
	dim act:act=lcase(Cls.fget("act",0))
	select case act
		case "adddb":adddb
		case "editdb":editdb
		case "del":del
		case "delsome":delsome
	end select
	
	sub adddb()
		dim p_Title,p_Info,p_Pic,p_Type,p_Content,p_UrlType,p_Url,p_Plug_Url,p_ClassId
		
		p_Title=Cls.enhtml(Cls.fpost("p_Title",0))
		p_ClassId=Cls.getint(Cls.fpost("p_ClassId",0),0)
		p_Info=cls.nohtml(Cls.enhtml(Cls.fpost("p_Info",0)))
		p_Pic=Cls.enhtml(Cls.fpost("p_Pic",0))
		p_Type=Cls.enhtml(Cls.fpost("p_Type",0))
		p_Content=Cls.fpost("p_Content",0)
		p_UrlType=Cls.enhtml(Cls.fpost("p_UrlType",0))
		If p_UrlType="外链" then
			p_Url=Cls.enhtml(Cls.fpost("p_Url",0))
		else
			p_Url=Cls.enhtml(Cls.fpost("p_Plug_Url",0))
		end if		
		p_Addtime=now()
		
		Dim data
		data=array(array("p_Title",p_Title,255,1),array("p_Info",p_Info,0,1),array("p_Pic",p_Pic,0,1),array("p_Addtime",p_Addtime,50,0),array("p_Type",p_Type,50,1),array("p_Content",p_Content,0,1),array("p_UrlType",p_UrlType,50,1),array("p_Url",p_Url,0,1),array("p_ClassId",p_ClassId,0,0))
		if Cls.db.dbnew("[Plug_PicMsg]",data,"")=1 then
			Cls.echo "1"
		else
			Cls.echo "0数据出错"
		end if	
		Cls.die
	end sub
	
	
	sub editdb()
		dim p_Title,p_Info,p_Pic,p_Type,p_Content,p_UrlType,p_Url,p_Plug_Url,p_ClassId
		dim id:id=Cls.getint(Cls.fget("id",0),0)
		
		p_Title=Cls.enhtml(Cls.fpost("p_Title",0))
		p_ClassId=Cls.getint(Cls.fpost("p_ClassId",0),0)
		p_Info=cls.nohtml(Cls.enhtml(Cls.fpost("p_Info",0)))
		p_Pic=Cls.enhtml(Cls.fpost("p_Pic",0))
		p_Type=Cls.enhtml(Cls.fpost("p_Type",0))
		p_Content=Cls.fpost("p_Content",0)
		p_UrlType=Cls.enhtml(Cls.fpost("p_UrlType",0))
		If p_UrlType="外链" then
			p_Url=Cls.enhtml(Cls.fpost("p_Url",0))
		else
			p_Url=Cls.enhtml(Cls.fpost("p_Plug_Url",0))
		end if
		
		Dim data
		data=array(array("p_Title",p_Title,255,1),array("p_Info",p_Info,0,1),array("p_Pic",p_Pic,0,1),array("p_Type",p_Type,50,1),array("p_Content",p_Content,0,1),array("p_UrlType",p_UrlType,50,1),array("p_Url",p_Url,0,1),array("p_ClassId",p_ClassId,0,0))
		if Cls.db.dbupdate("[Plug_PicMsg]","p_Id="&id,data)=1 then
			Cls.echo "1"
		else
			Cls.echo "0数据出错"
		end if	
		Cls.die	
	end sub
	
	
	sub del()
		dim id:id=Cls.getint(Cls.fget("id",0),0)
		if id>0 then
			Cls.db.dbdel "[Plug_PicMsg]","p_id="&id&""			
			Cls.db.dbdel "[sys_KeyWord]","k_plugName='PicMsg' and k_plugParam="&id&""	'删除关键字已指定的素材
		end if
		Cls.echo "1"
		Cls.die
	end sub
	
	sub delsome()
		dim id:id=Cls.enhtml(Cls.fget("id",0))
		dim idarr:idarr=split(id,",")
		if ubound(idarr)<0 then
			Cls.echo "0至少选择一条信息"
		else
			dim i
			for i=0 to ubound(idarr)
				if not isnumeric(idarr(i)) then
					Cls.echo "0参数："&id(i)&"不正确，请确认后再操作"
					exit sub
				else							
					Cls.db.dbdel "[sys_KeyWord]","k_plugName='PicMsg' and k_plugParam="&id&""	'删除关键字已指定的素材	
					''''''''如果多图文，删除	
				end if
			next	
			Cls.db.dbdel "[Plug_PicMsg]","p_id in("&id&")"
			Cls.echo "1"
		end if
		Cls.die
	end sub
	
%>
<!--#include file="../Plug_Top.asp"-->
<script language="javascript" src="../../lib/xheditor/xheditor-1.2.1.min.js"></script>
<script language="javascript" src="../../lib/xheditor/xheditor_lang/zh-cn.js"></script>
<script>
function checkadd(the)
{
	if($.trim(the.p_Title.value)=="")
	{
		$.message({content:"标题不能为空"});
		the.p_Title.focus();
		return false;
	}
//	if($.trim(the.p_Info.value)=="")
//	{
//		$.message({content:"简介不能为空"});
//		the.p_Info.focus();
//		return false;
//	}
//	if($.trim(the.p_Pic.value)=="")
//	{
//		$.message({content:"缩略图不能为空"});
//		the.p_Pic.focus();
//		return false;
//	}
	if($('#p_Type option:selected').val()=="链接"){		
		
		if($('#p_UrlType option:selected').val()=="外链"){
			if($.trim(the.p_Url.value)=="http://"){
				$.message({content:"链接不能为空"});
				the.p_Url.focus();
				return false;
			}
		}else{
			if($.trim(the.p_Plug_Url.value)=="0"){
				$.message({content:"请选择插件"});
				return false;
			}
		}
	}
	var url,data;
	url="?act=adddb";
	data="p_Title="+encodeURIComponent($.trim(the.p_Title.value));
	data+="&p_ClassId="+encodeURIComponent($.trim(the.p_ClassId.value));
	data+="&p_Info="+encodeURIComponent($.trim(the.p_Info.value));
	data+="&p_Pic="+encodeURIComponent($.trim(the.p_Pic.value));
	data+="&p_Type="+encodeURIComponent($.trim(the.p_Type.value));
	data+="&p_Content="+encodeURIComponent(editor.getSource());
	data+="&p_UrlType="+encodeURIComponent($.trim(the.p_UrlType.value));
	data+="&p_Url="+encodeURIComponent($.trim(the.p_Url.value));
	data+="&p_Plug_Url="+encodeURIComponent($.trim(the.p_Plug_Url.value));
	
	$.ajax({
	type:"post",
	cache:false,
	url:url,
	data:data,
	error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
	success:function(_)
	{
		var act=_.substring(0,1);
		var info=_.substring(1);
		switch(act)
		{
			case "0":
				$.message({type:"error",content:info});
				break;
			case "1":
				$.message({type:"ok",content:"保存成功"});
				setTimeout("location.href='?'",1000);
				break;
			default:
				alert(_)
				break;
		}
	}
	});
	return false

}

function checkedit(the,id)
{
	if($.trim(the.p_Title.value)=="")
	{
		$.message({content:"标题不能为空"});
		the.p_Title.focus();
		return false;
	}
//	if($.trim(the.p_Info.value)=="")
//	{
//		$.message({content:"简介不能为空"});
//		the.p_Info.focus();
//		return false;
//	}
//	if($.trim(the.p_Pic.value)=="")
//	{
//		$.message({content:"缩略图不能为空"});
//		the.p_Pic.focus();
//		return false;
//	}
	if($('#p_Type option:selected').val()=="链接"){		
		
		if($('#p_UrlType option:selected').val()=="外链"){
			if($.trim(the.p_Url.value)=="http://"){
				$.message({content:"链接不能为空"});
				the.p_Url.focus();
				return false;
			}
		}else{
			if($.trim(the.p_Plug_Url.value)=="0"){
				$.message({content:"请选择插件"});
				return false;
			}
		}
	}
	var url,data;
	url="?act=editdb&id="+id+"";
	data="p_Title="+encodeURIComponent($.trim(the.p_Title.value));
	data+="&p_ClassId="+encodeURIComponent($.trim(the.p_ClassId.value));
	data+="&p_Info="+encodeURIComponent($.trim(the.p_Info.value));
	data+="&p_Pic="+encodeURIComponent($.trim(the.p_Pic.value));
	data+="&p_Type="+encodeURIComponent($.trim(the.p_Type.value));
	data+="&p_Content="+encodeURIComponent(editor.getSource());
	data+="&p_UrlType="+encodeURIComponent($.trim(the.p_UrlType.value));
	data+="&p_Url="+encodeURIComponent($.trim(the.p_Url.value));
	data+="&p_Plug_Url="+encodeURIComponent($.trim(the.p_Plug_Url.value));
	
	$.ajax({
	type:"post",
	cache:false,
	url:url,
	data:data,
	error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
	success:function(_)
	{
		var act=_.substring(0,1);
		var info=_.substring(1);
		switch(act)
		{
			case "0":
				$.message({type:"error",content:info});
				break;
			case "1":
				$.message({type:"ok",content:"保存成功"});
				setTimeout("location.href='?'",1000);
				break;
			default:
				alert(_)
				break;
		}
	}
	});
	return false

}
$(function(){
	$(".del").click(function(){
		var id=this.getAttribute('rel');
		var throughBox=$.dialog.through;
			throughBox({
				icon:'question',
				content:'确定要删除？不可恢复！删除图文素材将会连带删除与之关联的关键字！',
				lock:true,
				opacity:'0.5',
				ok:function(){
					var url='?act=del&id='+id;
					$.ajax({
					type:"get",
					cache:false,
					url:url,
					error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
					success:function(_)
					{
						if(_.substring(0,1)==0)
						{
							$.message({type:"error",content:_.substring(1)});
						}
						else
						{
							$.message({type:"ok",content:"删除成功"});
							$("#list_"+id).fadeOut('slow');
						}
					}
					});
									
					},
				cancelVal:'取消',
				cancel:true 
			})
		
		})
	
	$(".delsome").click(function(){
		    var arrchk=$("input[name='id']:checked");
			var idarr="";
			$(arrchk).each(function(){
				if(idarr==""){idarr+=this.value}else{idarr+=","+this.value}                   
			}); 
			if(idarr=="")
			{
				$.message({content:"至少选择一条信息"});
			}
			else
			{
				var throughBox=$.dialog.through;
				throughBox({
				icon:'question',
				content:'确定要删除？不可恢复！删除图文素材将会连带删除与之关联的关键字！',
				lock:true,
				opacity:'0.5',
				ok:function(){
					var url='?act=delsome&id='+idarr;
					$.ajax({
					type:"get",
					cache:false,
					url:url,
					error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
					success:function(_)
					{
						var act=_.substring(0,1);
						var info=_.substring(1);
						switch(act)
						{
							case "0":
								$.message({type:"error",content:info});
								break;
							case "1":
								$.message({type:"ok",content:"删除成功"});
								var idnum;
								idnum=idarr.split(",")
								for(i=0;i<=idnum.length;i++)
								{
									$("#list_"+idnum[i]).fadeOut('slow');
								}
								break;
							default:
								alert(_);
								break;
						}
					}
					});
									
					},
				cancelVal:'取消',
				cancel:true 
			})
			}
		})
	
 })


function setclose(t0)
{
	if(t0=="图文"){$("#type_url").css("display","none");$("#type_pic").css("display","block");}else{$("#type_url").css("display","block");$("#type_pic").css("display","none");}
}
function setclose2(t0)
{
	if(t0=="外链"){$("#p_Plug_Url").css("display","none");$("#p_Url").css("display","");}else{$("#p_Plug_Url").css("display","");$("#p_Url").css("display","none");}
}

var editor;
$(pageInit);
function pageInit()
{
    var allPlugin={
        GetPic:{c:'GetPic',t:'图片上传',e:function(){
            g = $.dialog.through;
			g({
				title: "图片上传",
				content: "<iframe src='../../lib/upload.asp?filetype=1' width='560' height='400' frameborder='0' id='swfupload'></iframe>",
				padding: "10px",
				lock: !0,
				opacity: "0.5",
				ok: function() {
					var a = $("#att-status", art.dialog.top.$("#swfupload")[0].contentWindow.document).html();
					if (null != a) {
						var b, d;
						b = a.substring(0, 1),
						d = a.substring(1),
						editor.pasteHTML("<img src='"+d+"' />")
					}
				},
				cancelVal: "取消",
				cancel: !0
			})
        }},
		map:{c:'btnMap',t:'插入Google地图',e:function(){
			var _this=this;
			_this.saveBookmark();
			_this.showIframeModal('Google 地图','../../lib/xheditor/googlemap/googlemap.html',function(v){
				_this.loadBookmark();
				_this.pasteHTML('<img src="'+v+'" />');
			},538,404);
		}}
    };
    editor=$('#p_Content').xheditor({plugins:allPlugin,width:'510',height:'500',showBlocktag:true});
}
</script>
<style type="text/css">
<!--
.GetPic {
	background:transparent url(../../images/icons2.png) no-repeat top left;
}
.btnMap {
	background:transparent url(../../images/icons2.png) no-repeat top right;
}
-->
</style>

</head>
<body>
<div id="notice"><span>当前位置：</span>插件 > <a href="?">图文素材</a></div>
	<%
	if act="edit" then	
	dim id:id=Cls.getint(Cls.fget("id",0),0)
	datadb=Cls.db.dbload("","p_Title,p_Info,p_Pic,p_Type,p_Content,p_UrlType,p_Url,p_ClassId","[Plug_PicMsg]","p_id="&id,"")
	%>
    <script>	
	$(function(){
		$("#<%if datadb(3,0)="图文" then%>type_url<%else%>type_pic<%end if%>").css("display","none");
		$("#<%if datadb(5,0)="外链" then%>p_Plug_Url<%else%>p_Url<%end if%>").css("display","none");
	})
	</script>
<div class="clear_fixed">
  <dl class="addlist">
    <form onSubmit="return checkedit(this,<%=id%>)">
      <dt><em>图文标题：</em>
        <input type="text" name="p_Title" size="50" value="<%=datadb(0,0)%>"/></dt>
      <dt><em>所属分类：</em>
        <select name="p_ClassId" id="p_ClassId">
      	<%datadb2=Cls.db.dbload("","c_id,c_ClassName","[Plug_PicMsg_class]","","c_id asc")
		if ubound(datadb2)>=0 then
		for i=0 to ubound(datadb2,2)%>
          <option value="<%=datadb2(0,i)%>" <%if datadb(7,0)=datadb2(0,i) then cls.echo " selected"%>><%=datadb2(1,i)%></option>
      <%next
	  end if%>
        </select>  本项只作为后台备注分类，不影响正常使用</dt>
      <dt><em>描述：</em>
        <textarea name="p_Info" cols="60" rows="5"><%=datadb(1,0)%></textarea>
      </dt>
      <dt><em>缩略图：</em>
        <input type="text" name="p_Pic" id="p_Pic" size="50" value="<%=datadb(2,0)%>" /> <input type="button" value="上传" config="p_Pic:1:0:1" class="bnt" /> 尺寸大小最好是360X200</dt>
      <dt><em>素材类型：</em>
        <select name="p_Type" id="p_Type" onChange="setclose(this.value)">
          <option value="图文" <%if datadb(3,0)="图文" then Cls.echo "selected"%>>图文</option>
          <option value="链接" <%if datadb(3,0)="链接" then Cls.echo "selected"%>>链接</option>
        </select>
        【链接】点击时直接链接到外部地址，【图文】直接显示内容</dt>
      <dt id="type_url"><em>链接类型：</em>
        <select name="p_UrlType" id="p_UrlType" onChange="setclose2(this.value)">
          <option value="外链" <%if datadb(5,0)="外链" then cls.echo "selected"%>>外部链接</option>
          <option value="插件" <%if datadb(5,0)="插件" then cls.echo "selected"%>>内部插件</option>
        </select>        
        <select name="p_Plug_Url" id="p_Plug_Url">
          <option value="0">请选择插件</option>
        <%datadb2=Cls.db.dbload("","p_Api,p_Title","[Plug]","p_Type=3 and p_IsLock='开启'","p_num asc")
		if ubound(datadb2)>=0 then
		for i=0 to ubound(datadb2,2)%>
          <option value="<%=weburl%><%=webroot%><%=datadb2(0,i)%>" <%if datadb(6,0)=weburl&webroot&datadb2(0,i) then cls.echo "selected"%>><%=datadb2(1,i)%></option>
      	<%next
	  	end if%>
        </select>
        <input type="text" name="p_Url" id="p_Url" size="60" value="<%=datadb(6,0)%>"/>
        </dt>
      <dt id="type_pic"><em>图文内容：</em>
        <textarea name="p_Content" id="p_Content" cols="60" rows="5"><%=datadb(4,0)%></textarea>
      </dt>
      <dd>
        <input type="submit" name="send" value="保存" />
        <input type="button" value="返回" onClick="location.href='javascript:history.go(-1)'" />
      </dd>
    </form>
  </dl>
</div>
<%elseif act="add" then%>
<div class="clear_fixed">
  <dl class="addlist">
    <form onSubmit="return checkadd(this)">
      <dt><em>图文标题：</em>
        <input type="text" name="p_Title" size="50" /></dt>
      <dt><em>所属分类：</em>
        <select name="p_ClassId" id="p_ClassId">
      	<%datadb2=Cls.db.dbload("","c_id,c_ClassName","[Plug_PicMsg_class]","","c_id asc")
		if ubound(datadb2)>=0 then
		for i=0 to ubound(datadb2,2)%>
          <option value="<%=datadb2(0,i)%>"><%=datadb2(1,i)%></option>
      <%next
	  end if%>
        </select>  本项只作为后台备注分类，不影响正常使用</dt>
      <dt><em>描述：</em>
        <textarea name="p_Info" cols="60" rows="5"></textarea>
      </dt>
      <dt><em>缩略图：</em>
        <input type="text" name="p_Pic" id="p_Pic" size="50" /> <input type="button" value="上传" config="p_Pic:1:0:1" class="bnt" /> 尺寸大小最好是360X200</dt>
      <dt><em>素材类型：</em>
        <select name="p_Type" id="p_Type" onChange="setclose(this.value)">
          <option value="图文">图文</option>
          <option value="链接">链接</option>
        </select>
        【链接】点击时直接链接到外部地址，【图文】直接显示内容</dt>
      <dt id="type_url" style="display:none"><em>链接类型：</em>
        <select name="p_UrlType" id="p_UrlType" onChange="setclose2(this.value)">
          <option value="外链">外部链接</option>
          <option value="插件">内部插件</option>
        </select>        
        <select name="p_Plug_Url" id="p_Plug_Url" style="display:none">
          <option value="0">请选择插件</option>
        <%datadb=Cls.db.dbload("","p_Api,p_Title","[Plug]","p_Type=3 and p_IsLock='开启'","p_num asc")
		if ubound(datadb)>=0 then
		for i=0 to ubound(datadb,2)%>
          <option value="<%=weburl%><%=webroot%><%=datadb(0,i)%>"><%=datadb(1,i)%></option>
      	<%next
	  	end if%>
        </select>
        <input type="text" name="p_Url" id="p_Url" size="60" value="http://"/>
        </dt>
      <dt id="type_pic"><em>图文内容：</em>
        <textarea name="p_Content" id="p_Content" cols="60" rows="5"></textarea>
      </dt>
      <dd>
        <input type="submit" name="send" value="保存" />
        <input type="button" value="返回" onClick="location.href='javascript:history.go(-1)'" />
      </dd>
    </form>
  </dl>
</div>
<%else

classid=Cls.getint(Cls.fget("classid",0),0)
key=Cls.enhtml(Cls.fget("key",0))
p_type=Cls.enhtml(Cls.fget("p_Type",0))
%>
<div class="clear_fixed">
  <div id="menu"><div class="search"><form action="?" method="get" onSubmit="return checksearch(this)"><input type="text" name="key" class="ip" value="<%if key<>"" then%><%=key%><%else%>请输入关键字<%end if%>" onFocus="if(this.value=='请输入关键字')this.value=''" onBlur="if(this.value=='')this.value='请输入关键字'" /><input type="submit" class="sbnt" value="查询" /></form></div>
    <dl>
      <dt><span><a href="?act=add">添加素材</a></span></dt>
      <dt><span><a href="Amin_Class.asp">分类设置</a></span></dt>
      <dt class="dropdown"><span><a href="javascript:;">批量操作↓</a></span>
        <ul>
          <li><a href="javascript:;" class="delsome">批量删除</a></li>
        </ul>
      </dt>
        <dt class="dropdown"><span><a href="javascript:;">所属分类</a></span><ul>
       <%datadb2=Cls.db.dbload("","c_id,c_ClassName","[Plug_PicMsg_class]","","c_id asc")
		if ubound(datadb2)>=0 then
		for i=0 to ubound(datadb2,2)%>
                <li><a href="?classid=<%=datadb2(0,i)%>"><%=datadb2(1,i)%></a></li>
      <%next
	  end if%>
            </ul>
        </dt>
        <dt class="dropdown"><span><a href="javascript:;">所属类型</a></span><ul>
                <li><a href="?p_Type=图文">图文</a></li>
                <li><a href="?p_Type=链接">链接</a></li>
            </ul>
        </dt>
    </dl>
  </div>
  <form>
    <table cellpadding="5" id="table">
      <tr>
        <th width="20"><input type="checkbox" name="chkall" style="border:0;" onClick="checkall(this.form)" title="全选/取消" /></th>
        <th width="80">ID</th>
        <th width="100">类型</th>
        <th width="150">分类</th>
        <th width="300">标题</th>
        <th>简介</th>
        <th width="200">添加时间</th>
        <th width="80">管理</th>
      </tr>
      <%
		dim whereStr
		whereStr="where 1=1 "
		If key<>"" then
			whereStr=whereStr&"and a.p_Title like '%"&key&"%'"
		end if
		If classid<>0 then
			whereStr=whereStr&"and a.p_ClassId="&classid&""
		end if
		If p_Type<>"" then
			whereStr=whereStr&"and a.p_Type ='"&p_Type&"'"
		end if
		Set Page = new Page_List
		Page.Con = Cls.db.conn		
		dim SqlStr:SqlStr="Select a.p_Id,a.p_Type,a.p_Title,a.p_Info,a.p_Addtime,b.c_id,b.c_ClassName from [Plug_PicMsg] a left join [Plug_PicMsg_class] b on b.c_id=a.p_ClassId "&whereStr&" order by a.p_Id desc"
		Page.Sql = SqlStr
		Page.PageSize = 15
		Set Rs = Page.Rs
		
		If not Rs.Bof or Rs.Eof Then
			For i = 1 To Page.PageSize%>
      <tr id="list_<%=rs("p_id")%>">
        <td align="center"><input name="id" type="checkbox" style="border:0;" value="<%=rs("p_id")%>" /></td>
        <td align="center" ><%=rs("p_id")%></td>
        <td align="center"><a href="?p_Type=<%=rs("p_Type")%>"><%=rs("p_Type")%></a></td>
        <td align="center"><a href="?classid=<%=rs("c_id")%>"><%=rs("c_ClassName")%></a></td>
        <td align="center"><a href="../../Plug/picMsg/Show.asp?id=<%=rs("p_id")%>" target="_blank"><%=rs("p_Title")%></a></td>
        <td align="center" ><%=cls.cutstr(cls.nohtml(rs("p_Info")),50,1)%></td>
        <td align="center" ><%=cls.format_time(rs("p_Addtime"),1)%></td>
        <td align="center" ><a href="?act=edit&id=<%=rs("p_id")%>">编辑</a>　<a href="javascript:;" class="del" rel="<%=rs("p_id")%>">删除</a></td>
      </tr><%
				Rs.MoveNext
			Next
		End If
		
		Call Page.ShowPage
		
		Rs.Close
		Set Rs = Nothing
		Set Page = Nothing%>
    </table>
  </form>
</div>
<%end if%>
</body>
</html>